﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using System.Data;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

public partial class FBList : AdminBase
    {

        private DataTable dc = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            grdbind();

        }

        public void grdbind()
        {
            using (Entities bll = new Entities())
            {
                var Bpl = bll.X_help.OrderByDescending(p => p.ID);
                PagedDataSource pds = new PagedDataSource();

            AspNetPager1.RecordCount = Bpl.Count();
            this.rptList.DataSource = Bpl.Skip((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize).ToList(); 
            this.rptList.DataBind();


       
            }
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {   //当页面页数改变时，执行这个方法；
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            grdbind();
        }


        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
        int id = Convert.ToInt32(e.CommandArgument);

        Entities bll = new Entities();
        X_help model = bll.X_help.First(p => p.ID == id);

        switch (e.CommandName.ToLower())
        {
            case "ibtntop":
                if (model.i == true)
                    model.IsTop = false;
                else
                    model.IsTop = true;
                break;
            case "ibtnlock":
                if (model.IsLock == true)
                    model.IsLock = false;
                else
                    model.IsLock = true;
                break;

            case "del":

                bll.L_Newss.Remove(model);
                bll.SaveChanges();
                break;

        }

        bll.SaveChanges();
        grdbind();
    }



    //通过openid取得名字
    public static string getimg(string Imges)
    {
        JArray imgs = (JArray)JsonConvert.DeserializeObject(Imges);
        string xxxx = "";
        foreach (var xx in imgs)
        {
            xxxx += "<img src="+xx+" width=120px >";
        }

        return xxxx;
    }


}
